En este apartado se presenta el proceso empleado para la creación del indicador del deficit diferencial de población con cobertura a servicios publicos. # Cargue de librerías.
##install.packages("tidymodels")
##install.packages("tidyverse")
##install.packages("skimr")
##install.packages("DataExplorer")
##install.packages("ggpubr")
##install.packages("univariateML")
##install.packages("GGally")
##install.packages("doParallel")
##install.packages("nortest")
#install.packages("janitor")
#install.packages("FactoMineR")
#install.packages("CGPfunctions")
##install.packages("vtree")
## Librerias importadas
library(vtree)
library(CGPfunctions)
library(FactoMineR)
library(janitor)##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
require(nortest)## Loading required package: nortest
library(corrplot)## corrplot 0.90 loaded
library(tidymodels)## Registered S3 method overwritten by 'tune':
## method from
## required_pkgs.model_spec parsnip
## ── Attaching packages ────────────────────────────────────── tidymodels 0.1.4 ──
## ✓ broom 0.7.9 ✓ recipes 0.1.17
## ✓ dials 0.0.10 ✓ rsample 0.1.0
## ✓ dplyr 1.0.7 ✓ tibble 3.1.5
## ✓ ggplot2 3.3.5 ✓ tidyr 1.1.4
## ✓ infer 1.0.0 ✓ tune 0.1.6
## ✓ modeldata 0.1.1 ✓ workflows 0.2.4
## ✓ parsnip 0.1.7 ✓ workflowsets 0.1.0
## ✓ purrr 0.3.4 ✓ yardstick 0.0.8
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## x purrr::discard() masks scales::discard()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## x recipes::step() masks stats::step()
## • Use suppressPackageStartupMessages() to eliminate package startup messages
library(tidyverse)## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ readr 2.0.1 ✓ forcats 0.5.1
## ✓ stringr 1.4.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x readr::col_factor() masks scales::col_factor()
## x purrr::discard() masks scales::discard()
## x dplyr::filter() masks stats::filter()
## x stringr::fixed() masks recipes::fixed()
## x dplyr::lag() masks stats::lag()
## x readr::spec() masks yardstick::spec()
library(skimr)
library(DataExplorer)
library(ggpubr)
library(univariateML)
library(GGally)## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
library(doParallel)## Loading required package: foreach
##
## Attaching package: 'foreach'
## The following objects are masked from 'package:purrr':
##
## accumulate, when
## Loading required package: iterators
## Loading required package: parallel
library(ggridges)
library(ggplot2)
library(viridis)## Loading required package: viridisLite
##
## Attaching package: 'viridis'
## The following object is masked from 'package:scales':
##
## viridis_pal
library(hrbrthemes)## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
## Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
## if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
library(readr)
library(scales)
library(dplyr)
library(tidyr)Se procede al cargue de la base.
## importo los datos del MGN
df <- read.csv('//Users//Thony//Documents//Data_Analyst_DANE//OCT 2021//MGN_ANM_MANZANA_r1.csv',
na.strings = "")##Analisis exploratorio de las variables a fines al indicador. Realizamos un analisis exploratiorio para conocer las condiciones actuales de las variables a procesar.
## ------------- EDA --------------------##
### Filtro de variables para los indicadores : Déficit diferencial de población con cobertura a servicios públicos y déficit de servicios públicos.
df_1 <- (df)[56:76]
summary(df$CD_LC_CM); ## codigo por localidad.## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 1.00 6.00 10.00 10.05 14.00 19.00 77
summary(df$NMB_LC_CM)## nombre por localidad.## Length Class Mode
## 43408 character character
### hacer un resumen de estadisticos
skim(df_1)| Name | df_1 |
| Number of rows | 43408 |
| Number of columns | 21 |
| _______________________ | |
| Column type frequency: | |
| numeric | 21 |
| ________________________ | |
| Group variables | None |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| TP19_EE_1 | 0 | 1 | 53.80 | 92.85 | 0 | 16 | 35 | 60 | 2844 | ▇▁▁▁▁ |
| TP19_EE_2 | 0 | 1 | 0.13 | 1.10 | 0 | 0 | 0 | 0 | 102 | ▇▁▁▁▁ |
| TP19_EE_E1 | 0 | 1 | 4.49 | 14.58 | 0 | 0 | 0 | 1 | 672 | ▇▁▁▁▁ |
| TP19_EE_E2 | 0 | 1 | 21.11 | 57.79 | 0 | 0 | 1 | 28 | 2795 | ▇▁▁▁▁ |
| TP19_EE_E3 | 0 | 1 | 18.66 | 58.56 | 0 | 0 | 0 | 16 | 1659 | ▇▁▁▁▁ |
| TP19_EE_E4 | 0 | 1 | 6.07 | 45.30 | 0 | 0 | 0 | 0 | 2059 | ▇▁▁▁▁ |
| TP19_EE_E5 | 0 | 1 | 1.92 | 19.38 | 0 | 0 | 0 | 0 | 1212 | ▇▁▁▁▁ |
| TP19_EE_E6 | 0 | 1 | 1.41 | 12.72 | 0 | 0 | 0 | 0 | 485 | ▇▁▁▁▁ |
| TP19_EE_E9 | 0 | 1 | 0.14 | 0.81 | 0 | 0 | 0 | 0 | 84 | ▇▁▁▁▁ |
| TP19_ACU_1 | 0 | 1 | 53.68 | 92.92 | 0 | 16 | 34 | 60 | 2842 | ▇▁▁▁▁ |
| TP19_ACU_2 | 0 | 1 | 0.26 | 2.33 | 0 | 0 | 0 | 0 | 214 | ▇▁▁▁▁ |
| TP19_ALC_1 | 0 | 1 | 53.55 | 92.87 | 0 | 15 | 34 | 60 | 2844 | ▇▁▁▁▁ |
| TP19_ALC_2 | 0 | 1 | 0.38 | 2.86 | 0 | 0 | 0 | 0 | 219 | ▇▁▁▁▁ |
| TP19_GAS_1 | 0 | 1 | 50.29 | 90.16 | 0 | 14 | 32 | 56 | 2830 | ▇▁▁▁▁ |
| TP19_GAS_2 | 0 | 1 | 2.97 | 9.04 | 0 | 0 | 1 | 3 | 420 | ▇▁▁▁▁ |
| TP19_GAS_9 | 0 | 1 | 0.68 | 2.31 | 0 | 0 | 0 | 1 | 320 | ▇▁▁▁▁ |
| TP19_RECB1 | 0 | 1 | 53.63 | 92.75 | 0 | 16 | 34 | 60 | 2846 | ▇▁▁▁▁ |
| TP19_RECB2 | 0 | 1 | 0.30 | 2.00 | 0 | 0 | 0 | 0 | 186 | ▇▁▁▁▁ |
| TP19_INTE1 | 0 | 1 | 40.27 | 80.40 | 0 | 9 | 23 | 42 | 2230 | ▇▁▁▁▁ |
| TP19_INTE2 | 0 | 1 | 12.98 | 19.64 | 0 | 2 | 8 | 17 | 1300 | ▇▁▁▁▁ |
| TP19_INTE9 | 0 | 1 | 0.68 | 2.32 | 0 | 0 | 0 | 1 | 320 | ▇▁▁▁▁ |
Como es de apreciarse que los valores tienen muchas diferencia, debido que para unas manzanas la cantidad de registros de viviendas puede llegar a ser cero y para otras puede llegar a ser más de 2000, se procede a manejar un ajuste relativo de la escala de valores por variable, creando la función “rescale.many”, respectivamente:
## rescalado lineal
rescale.many <- function(dataframe,cols){
names <- names(dataframe)
for (col in cols){
name <- paste(names[col],"rescaled",sep = ".")
dataframe[name] <- scales::rescale(dataframe[,col])
}
cat(paste("Hemos reescalado",length(cols),"variables(s)"))
dataframe
}Aplicando la función se obtiene:
####--Aplicando rescale.many
df_2 <- rescale.many(df_1,c(1:21))## Hemos reescalado 21 variables(s)
df_3 <- df_2[22:42]
head(df_3)Debido a que no se desea tener duplicidad de la información se procede entonces a eliminar las variables por estrato para las que cuentan con servicios de electricidad por estratos.
df_3[3:8] <- NULLSe procede a analizar la matriz de correlaciones:
### matriz de correlaciones.
corr <- cor(df_3)
corrplot(corr,method = "circle", cl.cex = 1,pch.cex = 1,tl.col = "Black",tl.cex = 0.7) Como es de notarse existe mucha presencia de par de variables que no se correlacionan, no obstante existe a su vez un patrón de correlación entre las variables que enuncian viviendas que cuentan con servicios.
Debido a que hasta el momento los datos muestran que una manzana puede o no tener un alto volumen de manzanas que tienen servicios publicos y otros que no, se dese conocer para todo el conjunto de variables 1 variable representativa para cada tipo de población, entendiendose que la población favorecida refiere a la idea que son todas aquellas cantidades de viviendas que manifiestan tener algun tipo de servicio publico y las no favorecida son aquellas que no cuentan con ningun tipo de servicio publico, por tanto es posible considerar la idea de agrupar estas dos poblaciones en 2 variables representativas del total de poblaciones. En ese orden de ideas, entonces es necesario determinar que operaciones es la que mejor condiciones estadisticamente aceptable permiten representar estas poblaciones, por lo que se crean dos posibles operaciones fiables a la hora de agruparlas, las cuales serían evaluadas para la selección solo de una atraves de test estadsiticos. Las dos operaciones son las siguientes: ## Aproximaciones de operaciones del indicador. # Primera aproximación: La aproximación con operación sumatoria de todas las poblaciones favorecidas: \[Sumatoria población favorecida = \sum Conteo de viviendas si cuentan con servicios\] la sumatoria de todas las poblaciones no favorecidas: \[Sumatoria población no favorecida = \sum Conteo de viviendas no cuentan con servicios\] # Segunda aproximación: La aproximación con operación promedio de todas las poblaciones favorecidas: \[Promedio población favorecida = \frac {\sum Conteo de viviendas si cuentan con servicios}{Cantidad de variables observadas}\] La aproximación con operación promedio de todas las poblaciones no favorecidas: \[Promedio población no favorecida = \frac {\sum Conteo de viviendas no cuentan con servicios}{Cantidad de variables observadas}\]
## Primera aproximación con operación sumatoria:
head(df_3)df_3$Poblacion_fav_aprox_1 <- rowSums(select(.data = df_3, contains(c("_1","B1","E1"))))
summary(df_3$Poblacion_fav_aprox_1)## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00000 0.03143 0.07037 0.11131 0.12280 5.68700
df_3$Poblacion_nofav_aprox_1 <- rowSums(select(.data = df_3, contains(c("_2","B2","E2"))))
## Segunda aproximación con operación promedio:
df_3$Poblacion_fav_aprox_2 <- rowMeans(select(.data = df_3, contains(c("_1","B1","E1"))))
df_3$Poblacion_nofav_aprox_2 <- rowMeans(select(.data = df_3, contains(c("_2","B2","E2"))))
## resumenes:
colSums(select(df_3,contains("fav")));## Poblacion_fav_aprox_1 Poblacion_nofav_aprox_1 Poblacion_fav_aprox_2
## 4831.6076 994.0462 1332.1577
## Poblacion_nofav_aprox_2
## 332.3148
summary(select(df_3,contains("fav")));## Poblacion_fav_aprox_1 Poblacion_nofav_aprox_1 Poblacion_fav_aprox_2
## Min. :0.00000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.03143 1st Qu.:0.003919 1st Qu.:0.009483
## Median :0.07037 Median :0.011905 Median :0.019811
## Mean :0.11131 Mean :0.022900 Mean :0.030689
## 3rd Qu.:0.12280 3rd Qu.:0.025409 3rd Qu.:0.034077
## Max. :5.68700 Max. :4.954359 Max. :1.780193
## Poblacion_nofav_aprox_2
## Min. :0.000000
## 1st Qu.:0.002292
## Median :0.004853
## Mean :0.007656
## 3rd Qu.:0.008715
## Max. :0.808863
colSums(select(df_3,contains("aprox_2")));## Poblacion_fav_aprox_2 Poblacion_nofav_aprox_2
## 1332.1577 332.3148
summary(select(df_3,contains("aprox_2")))## Poblacion_fav_aprox_2 Poblacion_nofav_aprox_2
## Min. :0.000000 Min. :0.000000
## 1st Qu.:0.009483 1st Qu.:0.002292
## Median :0.019811 Median :0.004853
## Mean :0.030689 Mean :0.007656
## 3rd Qu.:0.034077 3rd Qu.:0.008715
## Max. :1.780193 Max. :0.808863
\[Fracción entre población favorecida vs no favorecida aprox 1= \frac {Poblacion fav aprox 1}{Poblacion no favo aprox 1}\]
"Fracción entre población favorecida vs no favorecida aproximación 1=" ## [1] "Fracción entre población favorecida vs no favorecida aproximación 1="
(4831.6086)/(994.0462)## [1] 4.860547
\[Fracción entre población favorecida vs no favorecida aprox 2= \frac {Poblacion fav aprox 2}{Poblacion no favo aprox 2}\]
"Fracción entre población favorecida vs no favorecida aproximación 2 =" ## [1] "Fracción entre población favorecida vs no favorecida aproximación 2 ="
(1332.1577)/(332.3148)## [1] 4.008722
La fracción entre población favorecida vs no favorecida segun la aproximación 2 es menor que la fracción de la operación suma(aprox 1), lo que quiere decir que a diferencia de la aproximación 1, la operación promedio regula mejor los outliers o cifras atipicas encontradas en los registros de la base de datos.
Para efectuar los analisis estadisticos es necesario corroborar la proveniencia de los datos, por tanto se busca establecer si existe prueba suficiente que permita evidenciar que los datos tienen comportamiento normal y por tanto es aceptable aplicarles supuestos estadisticos para explicar diferentes sucesos ya sea la igualdad de variabilidad que permita resaltar la pertinencia de uno de las dos aproximaciones.
####---------------------- Analisis estadistico ----------------###
par(mfrow = c(2,2))
qqnorm(df_3$Poblacion_fav_aprox_1, main = "Deficit poblaciones favorecidas \n Aproximación 1 (Suma)")
qqline(df_3$Poblacion_fav_aprox_1, col = "red")
qqnorm(df_3$Poblacion_nofav_aprox_1, main = "Deficit poblaciones desfavorecidas \n Aproximación 1 (Suma)")
qqline(df_3$Poblacion_nofav_aprox_1, col = "red")
qqnorm(df_3$Poblacion_fav_aprox_2, main = "Deficit poblaciones favorecidas \n Aproximación 2 (Promedio)")
qqline(df_3$Poblacion_fav_aprox_2, col = "red")
qqnorm(df_3$Poblacion_nofav_aprox_2, main = "Deficit poblaciones desfavorecidas \n Aproximación 2 (Promedio)")
qqline(df_3$Poblacion_nofav_aprox_2, col = "red") Ninguna de las variables cumple con el supuesto de normalidad dado por los graficos quantiles por quantiles. ## Test de Kolmogorov para supuestos de normalidad.
### test de normalidad kolmogorov
ks.test(x = df_3$Poblacion_fav_aprox_1 ,
"pnorm", mean(df_3$Poblacion_fav_aprox_1), sd(df_3$Poblacion_fav_aprox_1));## Warning in ks.test(x = df_3$Poblacion_fav_aprox_1, "pnorm",
## mean(df_3$Poblacion_fav_aprox_1), : ties should not be present for the
## Kolmogorov-Smirnov test
##
## One-sample Kolmogorov-Smirnov test
##
## data: df_3$Poblacion_fav_aprox_1
## D = 0.28689, p-value < 2.2e-16
## alternative hypothesis: two-sided
ks.test(x = df_3$Poblacion_nofav_aprox_1 ,
"pnorm", mean(df_3$Poblacion_nofav_aprox_1), sd(df_3$Poblacion_nofav_aprox_1));## Warning in ks.test(x = df_3$Poblacion_nofav_aprox_1, "pnorm",
## mean(df_3$Poblacion_nofav_aprox_1), : ties should not be present for the
## Kolmogorov-Smirnov test
##
## One-sample Kolmogorov-Smirnov test
##
## data: df_3$Poblacion_nofav_aprox_1
## D = 0.34391, p-value < 2.2e-16
## alternative hypothesis: two-sided
ks.test(x = df_3$Poblacion_fav_aprox_2 ,
"pnorm", mean(df_3$Poblacion_fav_aprox_2), sd(df_3$Poblacion_fav_aprox_2));## Warning in ks.test(x = df_3$Poblacion_fav_aprox_2, "pnorm",
## mean(df_3$Poblacion_fav_aprox_2), : ties should not be present for the
## Kolmogorov-Smirnov test
##
## One-sample Kolmogorov-Smirnov test
##
## data: df_3$Poblacion_fav_aprox_2
## D = 0.27791, p-value < 2.2e-16
## alternative hypothesis: two-sided
ks.test(x = df_3$Poblacion_nofav_aprox_2 ,
"pnorm", mean(df_3$Poblacion_nofav_aprox_2), sd(df_3$Poblacion_nofav_aprox_2))## Warning in ks.test(x = df_3$Poblacion_nofav_aprox_2, "pnorm",
## mean(df_3$Poblacion_nofav_aprox_2), : ties should not be present for the
## Kolmogorov-Smirnov test
##
## One-sample Kolmogorov-Smirnov test
##
## data: df_3$Poblacion_nofav_aprox_2
## D = 0.28057, p-value < 2.2e-16
## alternative hypothesis: two-sided
Todos los p-values se encuentran por debajo del valor de significancia es decir del 0.05 cuya probabilidad hace referencia a que no se encuentran distribuidos normalmente estas variables. ## Test de diferencias estadisticamente significativas Se presenta el test de Fligner-Killeen
########### ---- Analisis de distancias de distribución de probabilidad----
### Test Levene diferencia estadistica entre dos poblaciones.
library(car)## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:purrr':
##
## some
## The following object is masked from 'package:dplyr':
##
## recode
### población que si tiene servicios vs población que no tiene - operación de sumatoria
fligner.test(x = list(df_3$Poblacion_fav_aprox_1,df_3$Poblacion_nofav_aprox_1));##
## Fligner-Killeen test of homogeneity of variances
##
## data: list(df_3$Poblacion_fav_aprox_1, df_3$Poblacion_nofav_aprox_1)
## Fligner-Killeen:med chi-squared = 24010, df = 1, p-value < 2.2e-16
### población que si tiene servicios vs población que no tiene - operación de promedio.
fligner.test(x = list(df_3$Poblacion_fav_aprox_2,df_3$Poblacion_nofav_aprox_2))##
## Fligner-Killeen test of homogeneity of variances
##
## data: list(df_3$Poblacion_fav_aprox_2, df_3$Poblacion_nofav_aprox_2)
## Fligner-Killeen:med chi-squared = 21511, df = 1, p-value < 2.2e-16
Una vez consturido y evaluado lo que serían los insumos para la construcción definitiva del indicador, se procede entonces a realizar las siguientes operaciones para cada conjunto de variable. ## Aproximacion absoluta 1 (operacioón sumas). Se obtiene a partir de la diferencia entre la sumatoria de población favorecida contra la desfavorecida. \[Deficit diferencial de población favorecida (aprox 1) = [Sumatoria población favorecida - Sumatoria población no favorecida]\]
library(ggplot2)
## calculo del diferencial de población favorecida aproximación 1 (operación suma)
df$Deficit_dpf_aprox1 <- df_3$Poblacion_fav_aprox_1 - df_3$Poblacion_nofav_aprox_1
summary(df$Deficit_dpf_aprox1);## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -4.71128 0.01940 0.05430 0.08841 0.09862 5.04675
skim(df$Deficit_dpf_aprox1);| Name | df$Deficit_dpf_aprox1 |
| Number of rows | 43408 |
| Number of columns | 1 |
| _______________________ | |
| Column type frequency: | |
| numeric | 1 |
| ________________________ | |
| Group variables | None |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| data | 0 | 1 | 0.09 | 0.19 | -4.71 | 0.02 | 0.05 | 0.1 | 5.05 | ▁▁▇▁▁ |
hist(x = df$Deficit_dpf_aprox1,col = "firebrick");ggplot(data = df, aes(x = df$Deficit_dpf_aprox1)) +
geom_histogram(aes(y = ..density.., fill = ..count..)) +
scale_fill_gradient(low = "#DCDCDC", high = "#7C7C7C") +
stat_function(fun = dnorm, colour = "firebrick",
args = list(mean = mean(df$Deficit_dpf_aprox1),
sd = sd(df$Deficit_dpf_aprox1))) +
ggtitle("Histograma con curva normal teórica") +
theme(plot.title = element_text(face = "bold", vjust = 2))## Warning: Use of `df$Deficit_dpf_aprox1` is discouraged. Use `Deficit_dpf_aprox1`
## instead.
## Warning: Use of `df$Deficit_dpf_aprox1` is discouraged. Use `Deficit_dpf_aprox1`
## instead.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Aproximacion absoluta 2 (operacioón promedio). Se obtiene a partir de la diferencia entre el promedio de población favorecida contra la desfavorecida. \[Deficit diferencial de población favorecida (aprox 2) = [Promedio población favorecida - Promedio población no favorecida]\]
## calculo del diferencial de población favorecida aproximación 2 (operación promedio)
df$Deficit_dpf_aprox2 <- df_3$Poblacion_fav_aprox_2 - df_3$Poblacion_nofav_aprox_2
summary(df$Deficit_dpf_aprox2);## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.124853 0.006293 0.014447 0.023034 0.025390 1.181064
skim(df$Deficit_dpf_aprox2);| Name | df$Deficit_dpf_aprox2 |
| Number of rows | 43408 |
| Number of columns | 1 |
| _______________________ | |
| Column type frequency: | |
| numeric | 1 |
| ________________________ | |
| Group variables | None |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| data | 0 | 1 | 0.02 | 0.04 | -0.12 | 0.01 | 0.01 | 0.03 | 1.18 | ▇▁▁▁▁ |
hist(x = df$Deficit_dpf_aprox2,col = "springgreen4");ggplot(data = df, aes(x = df$Deficit_dpf_aprox2)) +
geom_histogram(aes(y = ..density.., fill = ..count..)) +
scale_fill_gradient(low = "#DCDCDC", high = "#7C7C7C") +
stat_function(fun = dnorm, colour = "firebrick",
args = list(mean = mean(df$Deficit_dpf_aprox2),
sd = sd(df$Deficit_dpf_aprox2))) +
ggtitle("Histograma con curva normal teórica")+
theme(plot.title = element_text(face = "bold", vjust = 2))## Warning: Use of `df$Deficit_dpf_aprox2` is discouraged. Use `Deficit_dpf_aprox2`
## instead.
## Warning: Use of `df$Deficit_dpf_aprox2` is discouraged. Use `Deficit_dpf_aprox2`
## instead.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Se emplea un test de leven para evaluar si existe una gran diferencia significativa entre los valores de las localidades de la ciudad de bogotá en función de cada aproximación se busca establecer con el estadistico Fisher, cual de las dos aproximaciones tiene menor diferentes en la distribución por localidad, respectivamente:
library(car)
### Levene Mu
leveneTest(y = df$Deficit_dpf_aprox1, group = df$NMB_LC_CM, center = "median");## Warning in leveneTest.default(y = df$Deficit_dpf_aprox1, group = df$NMB_LC_CM, :
## df$NMB_LC_CM coerced to factor.
### Levene Suma
leveneTest(y = df$Deficit_dpf_aprox2, group = df$NMB_LC_CM, center = "median")## Warning in leveneTest.default(y = df$Deficit_dpf_aprox2, group = df$NMB_LC_CM, :
## df$NMB_LC_CM coerced to factor.
Verificando las condiciones de normalidad para estas aproximaciones absolutas se obtiene:
### verificacion de normalidad de las nuevas aproximaciones absolutas.
par(mfrow = c(1,2))
qqnorm(df$Deficit_dpf_aprox1, main = "Deficit diferencial de población \nfavorecida operación Sumatoria")
qqline(df$Deficit_dpf_aprox1, col = "red")
qqnorm(df$Deficit_dpf_aprox2, main = "Deficit diferencial de población \nfavorecida operación Promedio")
qqline(df$Deficit_dpf_aprox2, col = "red") Aproximación del indicador seleccionado: “Indicador déficit diferencial de población favorecida con operación sumatoria”.
Se procede a rescalar el indicador seleccionado, y posteriormente a una visualización de la distribución en densidad del histograma de los datos.
#### ---- Indicador seleccionado : Diferencial de poblaciones favorecidas vs no favorecidas de la operación suma -----##
df$Deficit_dpf_aprox1.rescale <- scales::rescale(df$Deficit_dpf_aprox1, to = c(0,100))
### plot ridge del indicador por localidad.
## se transforman los nombres de las localidades en factores
df$NMB_LC_CM<- factor(df$NMB_LC_CM)
ggplot(df, aes(x = `Deficit_dpf_aprox1.rescale`, y = `NMB_LC_CM`, fill = ..x..)) +
geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
scale_fill_viridis(name = "Medición del Déficit diferencial población con \ncobertura servicios publicos por localidad| Bogotá", option = "C") +
labs(title = 'MGN- Nivel Manzana :Dataset 2021') +
theme_ipsum() +
theme(
legend.position = "top" ,
panel.spacing = unit(0.1, "lines"),
strip.text.x = element_text(size = 8)
)## Picking joint bandwidth of 0.12
## Categorizando los valores del indicador “Déficit diferencial de población con cobertura a servicios publicos”.
### categorización de variables numericas
valores<- c(-Inf,0,20,40,49,51,60,80,100)
categorias <- c("Crítico Deficit","Alto Deficit","Medio Deficit","Deficit","Equilibrio","Superavit","Medio Superavit","Alto Superavit")
df$Categorias_indicador_dpf <- cut(df$Deficit_dpf_aprox1.rescale, breaks = valores, labels = categorias)
summary(df$Categorias_indicador_dpf)## Crítico Deficit Alto Deficit Medio Deficit Deficit Equilibrio
## 1 1 9 26167 15067
## Superavit Medio Superavit Alto Superavit
## 1852 299 12
Se proceden a realizar operaciones y conversiones de los datos para un análisis descriptivo de la tabla de contingencia realizada a través del indicador dpf(diferencial de población favorecida).
### Analisis descriptivo de variables categoricas
# Modificando el nombre se obtiene
colnames(df)[106] <- "Deficit_dpf"
## Se organizan la información seleccionando las columnas utiles para la contrucción de la tabla cruzada.
pivot_df <- df %>%
select(Deficit_dpf,Categorias_indicador_dpf,
NMB_LC_CM)
## Se crean un nuevo data frame con la operación promedios busca caracterizar para cada categoria un valor promedio del indicador para cada localidad.
pivot_df <- pivot_df %>%
group_by(NMB_LC_CM, Categorias_indicador_dpf) %>%
summarise(Prom_ind_dpf = mean(Deficit_dpf))## `summarise()` has grouped output by 'NMB_LC_CM'. You can override using the `.groups` argument.
## Se emplea el uso de la función pivot_wider para crear la tabla cruzada.
pivot <- pivot_wider(pivot_df, names_from = Categorias_indicador_dpf,
values_from = Prom_ind_dpf)
## Transformando los valores de nombre de localidades a un tipo caracter.
pivot$NMB_LC_CM <- as.character(pivot$NMB_LC_CM)
## Se modifican las celdas vacias por ceros y por "No registros" para el nombre de la localidad.
pivot$NMB_LC_CM[20] = ""
pivot$NMB_LC_CM[20] = "NO REGISTRO"
## Convirtiendo en cero los NA's
pivot;pivot$Equilibrio <- ifelse(is.na(pivot$Equilibrio),0,pivot$Equilibrio)
pivot$Superavit <- ifelse(is.na(pivot$Superavit),0,pivot$Superavit)
pivot$`Medio Superavit` <- ifelse(is.na(pivot$`Medio Superavit`),0,pivot$`Medio Superavit`)
pivot$`Alto Superavit` <- ifelse(is.na(pivot$`Alto Superavit`),0,pivot$`Alto Superavit`)
pivot$`Alto Deficit` <- ifelse(is.na(pivot$`Alto Deficit`),0,pivot$`Alto Deficit`)
pivot$`Crítico Deficit` <- ifelse(is.na(pivot$`Crítico Deficit`),0,1)
pivot$`Medio Deficit` <- ifelse(is.na(pivot$`Medio Deficit`),0,pivot$`Medio Deficit`)
pivot;pivot1 <- pivot[,-(1)]
rownames(pivot1) <- pivot$NMB_LC_CM## Warning: Setting row names on a tibble is deprecated.
pivot1;### PCA
pca_pivot1 <- PCA(pivot1, graph = F)
plot(pca_pivot1, choix = "ind");## Warning: ggrepel: 13 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
plot(pca_pivot1, choix = "var");## Heat map--
library(RColorBrewer)
coul <- colorRampPalette(brewer.pal(8, "PiYG"))(25)
###-------
matrix_pivot <- as.matrix(pivot1)
heatmap(matrix_pivot, scale = "column",
main = "Heatmap tabla contingencia indicador",
Colv = NA, Rowv = NA, cexRow = 1, cexCol = 0.8,margins = c(8,1));library(factoextra)## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
pca_data <- prcomp(pivot1, scale = T)
fviz_eig(pca_data)fviz_pca_ind(pca_data,
col.ind = "cos2", # Color by the quality of representation
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
);## Warning: ggrepel: 13 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
fviz_pca_var(pca_data,
col.var = "contrib", # Color by contributions to the PC
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
);fviz_pca_biplot(pca_data, repel = TRUE,
col.var = "#2E9FDF", # Variables color
col.ind = "#696969" # Individuals color
)## Warning: ggrepel: 13 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
#### analisis de tablas cruzadas
pivot_df$NMB_LC_CM <- as.character(pivot_df$NMB_LC_CM)
pivot_df$NMB_LC_CM[66] <- "NO REGISTRADO"
pivot_df$Categorias_indicador_dpf <- as.character(pivot_df$Categorias_indicador_dpf)
library(CGPfunctions)
PlotXTabs2(pivot_df,NMB_LC_CM,Categorias_indicador_dpf,
x.axis.orientation = "vertical", label.text.size = 3);## `mutate_if()` ignored the following grouping variables:
## Column `x`
## `mutate_if()` ignored the following grouping variables:
## Column `x`
##- Arboles de proporción
library(vtree)
vtree(pivot_df,"Categorias_indicador_dpf", sortfill = T);vtree(pivot_df,"NMB_LC_CM", sortfill = T)## Guardando y agregando las variables para posteriores analisis.
head(df_3)summary(select(df_3,contains(c("_1","B1","E1","_2","B2","E2"))));## TP19_EE_1.rescaled TP19_ACU_1.rescaled TP19_ALC_1.rescaled TP19_GAS_1.rescaled
## Min. :0.000000 Min. :0.00000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.005626 1st Qu.:0.00563 1st Qu.:0.005274 1st Qu.:0.004947
## Median :0.012307 Median :0.01196 Median :0.011955 Median :0.011307
## Mean :0.018919 Mean :0.01889 Mean :0.018830 Mean :0.017770
## 3rd Qu.:0.021097 3rd Qu.:0.02111 3rd Qu.:0.021097 3rd Qu.:0.019788
## Max. :1.000000 Max. :1.00000 Max. :1.000000 Max. :1.000000
## Poblacion_fav_aprox_1 Poblacion_nofav_aprox_1 TP19_RECB1.rescaled
## Min. :0.00000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.03143 1st Qu.:0.003919 1st Qu.:0.005622
## Median :0.07037 Median :0.011905 Median :0.011947
## Mean :0.11131 Mean :0.022900 Mean :0.018844
## 3rd Qu.:0.12280 3rd Qu.:0.025409 3rd Qu.:0.021082
## Max. :5.68700 Max. :4.954359 Max. :1.000000
## TP19_INTE1.rescaled TP19_EE_2.rescaled TP19_ACU_2.rescaled TP19_ALC_2.rescaled
## Min. :0.000000 Min. :0.000000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.004036 1st Qu.:0.000000 1st Qu.:0.000000 1st Qu.:0.000000
## Median :0.010314 Median :0.000000 Median :0.000000 Median :0.000000
## Mean :0.018056 Mean :0.001269 Mean :0.001199 Mean :0.001741
## 3rd Qu.:0.018834 3rd Qu.:0.000000 3rd Qu.:0.000000 3rd Qu.:0.000000
## Max. :1.000000 Max. :1.000000 Max. :1.000000 Max. :1.000000
## TP19_GAS_2.rescaled Poblacion_fav_aprox_2 Poblacion_nofav_aprox_2
## Min. :0.000000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.000000 1st Qu.:0.009483 1st Qu.:0.002292
## Median :0.002381 Median :0.019811 Median :0.004853
## Mean :0.007069 Mean :0.030689 Mean :0.007656
## 3rd Qu.:0.007143 3rd Qu.:0.034077 3rd Qu.:0.008715
## Max. :1.000000 Max. :1.780193 Max. :0.808863
## TP19_RECB2.rescaled TP19_INTE2.rescaled
## Min. :0.000000 Min. :0.000000
## 1st Qu.:0.000000 1st Qu.:0.001538
## Median :0.000000 Median :0.006154
## Mean :0.001635 Mean :0.009988
## 3rd Qu.:0.000000 3rd Qu.:0.013077
## Max. :1.000000 Max. :1.000000
df[108:122] <- select(df_3,contains(c("_1","B1","E1","_2","B2","E2")))## Warning in `[<-.data.frame`(`*tmp*`, 108:122, value =
## structure(list(TP19_EE_1.rescaled = c(0.00140646976090014, : provided 16
## variables to replace 15 variables
summary(df);## DPTO_CCDGO MPIO_CCDGO CLAS_CCDGO SETR_CCDGO
## Min. :11 Min. :1 Min. :1.000 Min. : 0.000000
## 1st Qu.:11 1st Qu.:1 1st Qu.:1.000 1st Qu.: 0.000000
## Median :11 Median :1 Median :1.000 Median : 0.000000
## Mean :11 Mean :1 Mean :1.002 Mean : 0.009653
## 3rd Qu.:11 3rd Qu.:1 3rd Qu.:1.000 3rd Qu.: 0.000000
## Max. :11 Max. :1 Max. :2.000 Max. :11.000000
##
## SECR_CCDGO ZU_CCDGO SETU_CCDGO SECU_CCDGO
## Min. :0.000000 Min. : 0.00000 Min. : 1 Min. : 1.00
## 1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:2535 1st Qu.: 2.00
## Median :0.000000 Median : 0.00000 Median :4525 Median : 3.00
## Mean :0.004239 Mean : 0.01661 Mean :4759 Mean : 4.07
## 3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:6402 3rd Qu.: 6.00
## Max. :5.000000 Max. :15.00000 Max. :9222 Max. :25.00
##
## MANZ_CCDGO AG_CCDGO DATO_ANM VERSION
## Min. : 1.00 Min. : 53793 Length:43408 Min. :2018
## 1st Qu.: 5.00 1st Qu.:145292 Class :character 1st Qu.:2018
## Median :10.00 Median :156776 Mode :character Median :2018
## Mean :13.59 Mean :158387 Mean :2018
## 3rd Qu.:18.00 3rd Qu.:168539 3rd Qu.:2018
## Max. :92.00 Max. :253743 Max. :2018
##
## AREA LATITUD LONGITUD DENSIDAD
## Min. : 32 Min. :3.890 Min. :-74.36 Min. :0.00000
## 1st Qu.: 1479 1st Qu.:4.569 1st Qu.:-74.15 1st Qu.:0.01954
## Median : 2624 Median :4.618 Median :-74.11 Median :0.04790
## Mean : 7333 Mean :4.625 Mean :-74.12 Mean :0.05215
## 3rd Qu.: 5155 3rd Qu.:4.685 3rd Qu.:-74.09 3rd Qu.:0.07974
## Max. :9064324 Max. :4.826 Max. :-74.01 Max. :0.57348
##
## CTNENCUEST TP3_1_SI TP3_2_NO TP3A_RI TP3B_TCN
## Min. : 0.00 Min. :0 Min. : 0.00 Min. :0 Min. :0
## 1st Qu.: 20.00 1st Qu.:0 1st Qu.: 20.00 1st Qu.:0 1st Qu.:0
## Median : 41.00 Median :0 Median : 41.00 Median :0 Median :0
## Mean : 62.78 Mean :0 Mean : 62.78 Mean :0 Mean :0
## 3rd Qu.: 69.00 3rd Qu.:0 3rd Qu.: 69.00 3rd Qu.:0 3rd Qu.:0
## Max. :4619.00 Max. :0 Max. :4619.00 Max. :0 Max. :0
##
## TP4_1_SI TP4_2_NO TP9_1_USO TP9_2_USO
## Min. : 0.0000 Min. : 0.00 Min. : 0.00 Min. : 0.0000
## 1st Qu.: 0.0000 1st Qu.: 20.00 1st Qu.: 17.00 1st Qu.: 0.0000
## Median : 0.0000 Median : 41.00 Median : 36.00 Median : 0.0000
## Mean : 0.5643 Mean : 62.22 Mean : 57.13 Mean : 0.8724
## 3rd Qu.: 0.0000 3rd Qu.: 69.00 3rd Qu.: 62.00 3rd Qu.: 1.0000
## Max. :180.0000 Max. :4619.00 Max. :4615.00 Max. :60.0000
##
## TP9_3_USO TP9_4_USO TP9_2_1_MI TP9_2_2_MI
## Min. : 0.000 Min. :0 Min. : 0.00000 Min. : 0.0000
## 1st Qu.: 0.000 1st Qu.:0 1st Qu.: 0.00000 1st Qu.: 0.0000
## Median : 2.000 Median :0 Median : 0.00000 Median : 0.0000
## Mean : 4.779 Mean :0 Mean : 0.08955 Mean : 0.5437
## 3rd Qu.: 6.000 3rd Qu.:0 3rd Qu.: 0.00000 3rd Qu.: 0.0000
## Max. :217.000 Max. :0 Max. :22.00000 Max. :56.0000
##
## TP9_2_3_MI TP9_2_4_MI TP9_2_9_MI TP9_3_1_NO
## Min. : 0.0000 Min. : 0.000000 Min. :0.000000 Min. : 0.0000
## 1st Qu.: 0.0000 1st Qu.: 0.000000 1st Qu.:0.000000 1st Qu.: 0.0000
## Median : 0.0000 Median : 0.000000 Median :0.000000 Median : 0.0000
## Mean : 0.2357 Mean : 0.001912 Mean :0.001567 Mean : 0.4621
## 3rd Qu.: 0.0000 3rd Qu.: 0.000000 3rd Qu.:0.000000 3rd Qu.: 0.0000
## Max. :46.0000 Max. :15.000000 Max. :4.000000 Max. :52.0000
##
## TP9_3_2_NO TP9_3_3_NO TP9_3_4_NO TP9_3_5_NO
## Min. : 0.000 Min. : 0.000 Min. : 0.00000 Min. : 0.0000
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.00000 1st Qu.: 0.0000
## Median : 0.000 Median : 0.000 Median : 0.00000 Median : 0.0000
## Mean : 2.263 Mean : 1.376 Mean : 0.01168 Mean : 0.1461
## 3rd Qu.: 2.000 3rd Qu.: 1.000 3rd Qu.: 0.00000 3rd Qu.: 0.0000
## Max. :180.000 Max. :173.000 Max. :24.00000 Max. :19.0000
##
## TP9_3_6_NO TP9_3_7_NO TP9_3_8_NO TP9_3_9_NO
## Min. : 0.0000 Min. : 0.0000 Min. : 0.000000 Min. : 0.00000
## 1st Qu.: 0.0000 1st Qu.: 0.0000 1st Qu.: 0.000000 1st Qu.: 0.00000
## Median : 0.0000 Median : 0.0000 Median : 0.000000 Median : 0.00000
## Mean : 0.2897 Mean : 0.1026 Mean : 0.002995 Mean : 0.00569
## 3rd Qu.: 0.0000 3rd Qu.: 0.0000 3rd Qu.: 0.000000 3rd Qu.: 0.00000
## Max. :109.0000 Max. :36.0000 Max. :11.000000 Max. :12.00000
##
## TP9_3_10_N TP9_3_99_N TVIVIENDA TP14_1_TIP
## Min. : 0.0000 Min. :0.00000 Min. : 0 Min. : 0.00
## 1st Qu.: 0.0000 1st Qu.:0.00000 1st Qu.: 17 1st Qu.: 5.00
## Median : 0.0000 Median :0.00000 Median : 37 Median : 12.00
## Mean : 0.1095 Mean :0.01037 Mean : 58 Mean : 19.03
## 3rd Qu.: 0.0000 3rd Qu.:0.00000 3rd Qu.: 63 3rd Qu.: 23.00
## Max. :21.0000 Max. :4.00000 Max. :4618 Max. :1773.00
##
## TP14_2_TIP TP14_3_TIP TP14_4_TIP TP14_5_TIP
## Min. : 0.00 Min. : 0.000 Min. :0.000000 Min. :0.000000
## 1st Qu.: 2.00 1st Qu.: 0.000 1st Qu.:0.000000 1st Qu.:0.000000
## Median : 13.00 Median : 1.000 Median :0.000000 Median :0.000000
## Mean : 35.43 Mean : 3.496 Mean :0.004055 Mean :0.003893
## 3rd Qu.: 34.00 3rd Qu.: 4.000 3rd Qu.:0.000000 3rd Qu.:0.000000
## Max. :4571.00 Max. :231.000 Max. :4.000000 Max. :5.000000
##
## TP14_6_TIP TP15_1_OCU TP15_2_OCU TP15_3_OCU
## Min. : 0.00000 Min. : 0.00 Min. : 0.0000 Min. : 0.000
## 1st Qu.: 0.00000 1st Qu.: 16.00 1st Qu.: 0.0000 1st Qu.: 0.000
## Median : 0.00000 Median : 35.00 Median : 0.0000 Median : 0.000
## Mean : 0.03845 Mean : 53.93 Mean : 0.7544 Mean : 0.591
## 3rd Qu.: 0.00000 3rd Qu.: 60.00 3rd Qu.: 0.0000 3rd Qu.: 0.000
## Max. :68.00000 Max. :2846.00 Max. :311.0000 Max. :149.000
##
## TP15_4_OCU TP16_HOG TP19_EE_1 TP19_EE_2
## Min. : 0.000 Min. : 0.00 Min. : 0.0 Min. : 0.0000
## 1st Qu.: 0.000 1st Qu.: 18.00 1st Qu.: 16.0 1st Qu.: 0.0000
## Median : 0.000 Median : 39.00 Median : 35.0 Median : 0.0000
## Mean : 2.722 Mean : 57.83 Mean : 53.8 Mean : 0.1294
## 3rd Qu.: 2.000 3rd Qu.: 66.00 3rd Qu.: 60.0 3rd Qu.: 0.0000
## Max. :1459.000 Max. :2863.00 Max. :2844.0 Max. :102.0000
##
## TP19_EE_E1 TP19_EE_E2 TP19_EE_E3 TP19_EE_E4
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.000
## 1st Qu.: 0.00 1st Qu.: 0.00 1st Qu.: 0.00 1st Qu.: 0.000
## Median : 0.00 Median : 1.00 Median : 0.00 Median : 0.000
## Mean : 4.49 Mean : 21.11 Mean : 18.66 Mean : 6.075
## 3rd Qu.: 1.00 3rd Qu.: 28.00 3rd Qu.: 16.00 3rd Qu.: 0.000
## Max. :672.00 Max. :2795.00 Max. :1659.00 Max. :2059.000
##
## TP19_EE_E5 TP19_EE_E6 TP19_EE_E9 TP19_ACU_1
## Min. : 0.000 Min. : 0.000 Min. : 0.0000 Min. : 0.00
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.0000 1st Qu.: 16.00
## Median : 0.000 Median : 0.000 Median : 0.0000 Median : 34.00
## Mean : 1.921 Mean : 1.407 Mean : 0.1376 Mean : 53.68
## 3rd Qu.: 0.000 3rd Qu.: 0.000 3rd Qu.: 0.0000 3rd Qu.: 60.00
## Max. :1212.000 Max. :485.000 Max. :84.0000 Max. :2842.00
##
## TP19_ACU_2 TP19_ALC_1 TP19_ALC_2 TP19_GAS_1
## Min. : 0.0000 Min. : 0.00 Min. : 0.0000 Min. : 0.00
## 1st Qu.: 0.0000 1st Qu.: 15.00 1st Qu.: 0.0000 1st Qu.: 14.00
## Median : 0.0000 Median : 34.00 Median : 0.0000 Median : 32.00
## Mean : 0.2565 Mean : 53.55 Mean : 0.3814 Mean : 50.29
## 3rd Qu.: 0.0000 3rd Qu.: 60.00 3rd Qu.: 0.0000 3rd Qu.: 56.00
## Max. :214.0000 Max. :2844.00 Max. :219.0000 Max. :2830.00
##
## TP19_GAS_2 TP19_GAS_9 TP19_RECB1 TP19_RECB2
## Min. : 0.000 Min. : 0.0000 Min. : 0.00 Min. : 0.000
## 1st Qu.: 0.000 1st Qu.: 0.0000 1st Qu.: 16.00 1st Qu.: 0.000
## Median : 1.000 Median : 0.0000 Median : 34.00 Median : 0.000
## Mean : 2.969 Mean : 0.6762 Mean : 53.63 Mean : 0.304
## 3rd Qu.: 3.000 3rd Qu.: 1.0000 3rd Qu.: 60.00 3rd Qu.: 0.000
## Max. :420.000 Max. :320.0000 Max. :2846.00 Max. :186.000
##
## TP19_INTE1 TP19_INTE2 TP19_INTE9 TP27_PERSO
## Min. : 0.00 Min. : 0.00 Min. : 0.0000 Min. : 0.0
## 1st Qu.: 9.00 1st Qu.: 2.00 1st Qu.: 0.0000 1st Qu.: 51.0
## Median : 23.00 Median : 8.00 Median : 0.0000 Median : 113.0
## Mean : 40.27 Mean : 12.98 Mean : 0.6844 Mean : 164.4
## 3rd Qu.: 42.00 3rd Qu.: 17.00 3rd Qu.: 1.0000 3rd Qu.: 191.0
## Max. :2230.00 Max. :1300.00 Max. :320.0000 Max. :8330.0
##
## PERSONAS_L PERSONAS_S TP32_1_SEX TP32_2_SEX
## Min. :0 Min. : 0.0 Min. : 0.00 Min. : 0.00
## 1st Qu.:0 1st Qu.: 51.0 1st Qu.: 25.00 1st Qu.: 26.00
## Median :0 Median : 113.0 Median : 55.00 Median : 58.00
## Mean :0 Mean : 164.4 Mean : 78.41 Mean : 86.01
## 3rd Qu.:0 3rd Qu.: 191.0 3rd Qu.: 92.00 3rd Qu.: 99.00
## Max. :0 Max. :8330.0 Max. :3787.00 Max. :4543.00
##
## TP34_1_EDA TP34_2_EDA TP34_3_EDA TP34_4_EDA
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
## 1st Qu.: 5.00 1st Qu.: 6.00 1st Qu.: 9.00 1st Qu.: 7.00
## Median : 13.00 Median : 16.00 Median : 22.00 Median : 17.00
## Mean : 19.74 Mean : 23.54 Mean : 31.45 Mean : 27.07
## 3rd Qu.: 24.00 3rd Qu.: 28.00 3rd Qu.: 38.00 3rd Qu.: 31.00
## Max. :1440.00 Max. :1400.00 Max. :1920.00 Max. :1857.00
##
## TP34_5_EDA TP34_6_EDA TP34_7_EDA TP34_8_EDA
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.000
## 1st Qu.: 5.00 1st Qu.: 5.00 1st Qu.: 3.00 1st Qu.: 1.000
## Median : 13.00 Median : 13.00 Median : 8.00 Median : 4.000
## Mean : 21.38 Mean : 19.56 Mean : 12.33 Mean : 6.198
## 3rd Qu.: 24.00 3rd Qu.: 23.00 3rd Qu.: 15.00 3rd Qu.: 8.000
## Max. :1031.00 Max. :676.00 Max. :393.00 Max. :208.000
##
## TP34_9_EDA TP51PRIMAR TP51SECUND TP51SUPERI
## Min. : 0.000 Min. : 0.00 Min. : 0.00 Min. : 0.00
## 1st Qu.: 0.000 1st Qu.: 0.00 1st Qu.: 0.00 1st Qu.: 0.00
## Median : 2.000 Median : 23.00 Median : 0.00 Median : 22.00
## Mean : 3.142 Mean : 31.19 Mean : 28.35 Mean : 43.58
## 3rd Qu.: 4.000 3rd Qu.: 43.00 3rd Qu.: 0.00 3rd Qu.: 45.00
## Max. :110.000 Max. :2094.00 Max. :4161.00 Max. :2793.00
##
## TP51POSTGR TP51_13_ED TP51_99_ED CD_LC_CM
## Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. : 1.00
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 6.00
## Median : 0.000 Median : 1.000 Median : 2.000 Median :10.00
## Mean : 7.644 Mean : 2.523 Mean : 3.557 Mean :10.05
## 3rd Qu.: 0.000 3rd Qu.: 3.000 3rd Qu.: 5.000 3rd Qu.:14.00
## Max. :1490.000 Max. :178.000 Max. :1130.000 Max. :19.00
## NA's :77
## NMB_LC_CM TP_LC_CM Shape_Leng
## CIUDAD BOLIVAR: 5248 Length:43408 Min. :0.0002113
## KENNEDY : 4966 Class :character 1st Qu.:0.0015705
## SUBA : 4740 Mode :character Median :0.0021684
## ENGATIVA : 4058 Mean :0.0027679
## BOSA : 3356 3rd Qu.:0.0029996
## (Other) :20963 Max. :0.1441678
## NA's : 77
## Shape_Area COD_RDTM geometry Deficit_dpf_aprox1
## Min. :2.600e-09 Min. :1.1e+23 Length:43408 Min. :-4.71128
## 1st Qu.:1.205e-07 1st Qu.:1.1e+23 Class :character 1st Qu.: 0.01940
## Median :2.139e-07 Median :1.1e+23 Mode :character Median : 0.05430
## Mean :5.977e-07 Mean :1.1e+23 Mean : 0.08841
## 3rd Qu.:4.201e-07 3rd Qu.:1.1e+23 3rd Qu.: 0.09862
## Max. :7.388e-04 Max. :1.1e+23 Max. : 5.04675
##
## Deficit_dpf_aprox2 Deficit_dpf Categorias_indicador_dpf
## Min. :-0.124853 Min. : 0.00 Deficit :26167
## 1st Qu.: 0.006293 1st Qu.: 48.48 Equilibrio :15067
## Median : 0.014447 Median : 48.84 Superavit : 1852
## Mean : 0.023034 Mean : 49.19 Medio Superavit: 299
## 3rd Qu.: 0.025390 3rd Qu.: 49.29 Alto Superavit : 12
## Max. : 1.181064 Max. :100.00 Medio Deficit : 9
## (Other) : 2
## TP19_EE_1.rescaled TP19_ACU_1.rescaled TP19_ALC_1.rescaled TP19_GAS_1.rescaled
## Min. :0.000000 Min. :0.00000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.005626 1st Qu.:0.00563 1st Qu.:0.005274 1st Qu.:0.004947
## Median :0.012307 Median :0.01196 Median :0.011955 Median :0.011307
## Mean :0.018919 Mean :0.01889 Mean :0.018830 Mean :0.017770
## 3rd Qu.:0.021097 3rd Qu.:0.02111 3rd Qu.:0.021097 3rd Qu.:0.019788
## Max. :1.000000 Max. :1.00000 Max. :1.000000 Max. :1.000000
##
## Poblacion_fav_aprox_1 Poblacion_nofav_aprox_1 TP19_RECB1.rescaled
## Min. :0.00000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.03143 1st Qu.:0.003919 1st Qu.:0.005622
## Median :0.07037 Median :0.011905 Median :0.011947
## Mean :0.11131 Mean :0.022900 Mean :0.018844
## 3rd Qu.:0.12280 3rd Qu.:0.025409 3rd Qu.:0.021082
## Max. :5.68700 Max. :4.954359 Max. :1.000000
##
## TP19_INTE1.rescaled TP19_EE_2.rescaled TP19_ACU_2.rescaled TP19_ALC_2.rescaled
## Min. :0.000000 Min. :0.000000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.004036 1st Qu.:0.000000 1st Qu.:0.000000 1st Qu.:0.000000
## Median :0.010314 Median :0.000000 Median :0.000000 Median :0.000000
## Mean :0.018056 Mean :0.001269 Mean :0.001199 Mean :0.001741
## 3rd Qu.:0.018834 3rd Qu.:0.000000 3rd Qu.:0.000000 3rd Qu.:0.000000
## Max. :1.000000 Max. :1.000000 Max. :1.000000 Max. :1.000000
##
## TP19_GAS_2.rescaled Poblacion_fav_aprox_2 Poblacion_nofav_aprox_2
## Min. :0.000000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.000000 1st Qu.:0.009483 1st Qu.:0.002292
## Median :0.002381 Median :0.019811 Median :0.004853
## Mean :0.007069 Mean :0.030689 Mean :0.007656
## 3rd Qu.:0.007143 3rd Qu.:0.034077 3rd Qu.:0.008715
## Max. :1.000000 Max. :1.780193 Max. :0.808863
##
## TP19_RECB2.rescaled
## Min. :0.000000
## 1st Qu.:0.000000
## Median :0.000000
## Mean :0.001635
## 3rd Qu.:0.000000
## Max. :1.000000
##
## Analisis de los valores de viviendas por manzanas.-----
residuos <- ((df_3$TP19_EE_1.rescaled + df_3$TP19_EE_2.rescaled) - (df_3$TP19_ACU_1.rescaled + df_3$TP19_ACU_2.rescaled))
hist(residuos, prob = T);
abline(v = mean(residuos), col = "red");
abline(v = median(residuos), col = "springgreen4");summary(residuos);## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.6525271 -0.0000151 -0.0000079 0.0001013 -0.0000027 0.2858776
En este apartado se presenta el proceso empleado para la creación del indicador del Déficit en cobertura de servicios publicos. Seleccionando las columnas para el indicador, se emplea la siguiente metodología:
### Se seleccionan las variables que manifiestan el conteo de viviendas que cuentan con servicios publicos.
data <- select(df, contains(c("TP19")))
data <- select(data, contains(c("_1","B1","E1")))
data$TP19_EE_E1 <- NULL
data$TVIVIENDA <- df$TVIVIENDA
head(data)## Visualizando los resumenes estadisticos:
summary(data)## TP19_EE_1 TP19_ACU_1 TP19_ALC_1 TP19_GAS_1
## Min. : 0.0 Min. : 0.00 Min. : 0.00 Min. : 0.00
## 1st Qu.: 16.0 1st Qu.: 16.00 1st Qu.: 15.00 1st Qu.: 14.00
## Median : 35.0 Median : 34.00 Median : 34.00 Median : 32.00
## Mean : 53.8 Mean : 53.68 Mean : 53.55 Mean : 50.29
## 3rd Qu.: 60.0 3rd Qu.: 60.00 3rd Qu.: 60.00 3rd Qu.: 56.00
## Max. :2844.0 Max. :2842.00 Max. :2844.00 Max. :2830.00
## TP19_EE_1.rescaled TP19_ACU_1.rescaled TP19_ALC_1.rescaled TP19_GAS_1.rescaled
## Min. :0.000000 Min. :0.00000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.005626 1st Qu.:0.00563 1st Qu.:0.005274 1st Qu.:0.004947
## Median :0.012307 Median :0.01196 Median :0.011955 Median :0.011307
## Mean :0.018919 Mean :0.01889 Mean :0.018830 Mean :0.017770
## 3rd Qu.:0.021097 3rd Qu.:0.02111 3rd Qu.:0.021097 3rd Qu.:0.019788
## Max. :1.000000 Max. :1.00000 Max. :1.000000 Max. :1.000000
## TP19_RECB1 TP19_RECB1.rescaled TP19_INTE1 TP19_INTE1.rescaled
## Min. : 0.00 Min. :0.000000 Min. : 0.00 Min. :0.000000
## 1st Qu.: 16.00 1st Qu.:0.005622 1st Qu.: 9.00 1st Qu.:0.004036
## Median : 34.00 Median :0.011947 Median : 23.00 Median :0.010314
## Mean : 53.63 Mean :0.018844 Mean : 40.27 Mean :0.018056
## 3rd Qu.: 60.00 3rd Qu.:0.021082 3rd Qu.: 42.00 3rd Qu.:0.018834
## Max. :2846.00 Max. :1.000000 Max. :2230.00 Max. :1.000000
## TVIVIENDA
## Min. : 0
## 1st Qu.: 17
## Median : 37
## Mean : 58
## 3rd Qu.: 63
## Max. :4618
Posteriormente realiza la sumatoria de las proporciones obtenidas, respectivamente: \[Sumatoria proporciones por servicio (SPS) = \sum \frac{Conteo viviendas por tipo "x" de servicios}{PTM}\]
## Calculo de proporciones::
data$TP19_EE_1.SPS <- (data$TP19_EE_1 / data$TVIVIENDA)
data$TP19_ACU_1.SPS <- (data$TP19_ACU_1 / data$TVIVIENDA)
data$TP19_ALC_1.SPS <- (data$TP19_ALC_1 / data$TVIVIENDA)
data$TP19_GAS_1.SPS <- (data$TP19_GAS_1 / data$TVIVIENDA)
data$TP19_RECB1.SPS <- (data$TP19_RECB1 / data$TVIVIENDA)
data$TP19_INTE1.SPS <- (data$TP19_INTE1 / data$TVIVIENDA)
## sumatoria de proporciones calculadas.
data$SPS <- rowSums(select(data, contains(".SPS")));
data$SPS <- ifelse(is.na(data$SPS),0,data$SPS)
##histograma::
hist(data$SPS, probability = F);
abline(v = mean(data$SPS), col = "firebrick") Detallando los calculos se estarían mencionando lo siguiente: \[SPS = \frac{Conteo viviendas por tipo electrico de servicios}{SPTM}+\frac{Conteo viviendas por tipo acueducto de servicios}{PTM}+...\] 2) Por ultimo se emplea la división por la cantidad de servicios: \[Deficit en cobertura de servicios publicos(Deficitcsp) = \frac{SPS}{6}\]
data$Deficit_csp <- (data$SPS / 6)*100
summary(data$Deficit_csp);## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 80.71 88.71 77.38 92.74 100.00
head(data);hist(data$Deficit_csp, probability = F);
abline(v = mean(data$Deficit_csp), col = "firebrick")Empleando los algoritmos afines para la construcción del análisis del indicador con tablas cruzadas se emplea entonces la categorización a partir de la escala de medida que permita medir de forma detallada la incidiencia del indicador en cada manzana, para el cual se establecen limites y clasificación de la medición del mismo. Para los siguientes rangos: \[[0,20]-> Alto déficit en cobertura de servicios públicos \\ [20,40] -> Medio déficit en cobertura de servicios públicos \\ [40,49] -> Déficit en cobertura de servicios públicos \\ [49,51] -> Equilibrio en cobertura de servicios públicos \\ [51,60] -> Superavit en cobertura de servicios públicos \\ [60,80] -> Medio superavit en cobertura de servicios públicos \\ [80,100] -> Alto superavit en cobertura de servicios públicos. \]
### Visualizaciones del indicador déficit csp.
dim(df)## [1] 43408 122
df[108] <- data$Deficit_csp
colnames(df)[108] <- "Deficit_csp"
## grafico de densidad por localidad.
ggplot(df, aes(x = `Deficit_csp`, y = `NMB_LC_CM`, fill = ..x..)) +
geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
scale_fill_viridis(name = "Medición del Déficit en cobertura cobertura de \nservicios publicos por localidad| Bogotá", option = "C") +
labs(title = 'MGN- Nivel Manzana :Dataset 2021') +
theme_ipsum() +
theme(
legend.position = "top" ,
panel.spacing = unit(0.1, "lines"),
strip.text.x = element_text(size = 8)
)## Picking joint bandwidth of 2.51
### categorización de variables numericas
values <- c(-Inf,20,40,49,51,60,80,100)
cat <- c("Alto Deficit","Medio Deficit","Deficit","Equilibrio","Superavit","Medio Superavit","Alto Superavit")
df$Categorias_indicador_csp<- cut(df$Deficit_csp, breaks = values, labels = cat)
summary(df$Categorias_indicador_csp)## Alto Deficit Medio Deficit Deficit Equilibrio Superavit
## 5005 202 188 68 415
## Medio Superavit Alto Superavit
## 4563 32967
### Analisis descriptivo de variables categoricas: Indicador csp
## Se organizan la información seleccionando las columnas utiles para la contrucción de la tabla cruzada.
pivot_df2 <- df %>%
select(Deficit_csp,Categorias_indicador_csp,
NMB_LC_CM)
## Se crean un nuevo data frame con la operación promedios busca caracterizar para cada categoria un valor promedio del indicador para cada localidad.
pivot_df2 <- pivot_df2 %>%
group_by(NMB_LC_CM, Categorias_indicador_csp) %>%
summarise(Prom_ind_csp = mean(Deficit_csp))## `summarise()` has grouped output by 'NMB_LC_CM'. You can override using the `.groups` argument.
## Se emplea el uso de la función pivot_wider para crear la tabla cruzada.
pivot2 <- pivot_wider(pivot_df2, names_from = Categorias_indicador_csp,
values_from = Prom_ind_csp)
## Transformando los valores de nombre de localidades a un tipo caracter.
pivot2$NMB_LC_CM <- as.character(pivot2$NMB_LC_CM)
## Se modifican las celdas por "No registros" para el nombre de la localidad.
pivot2;pivot2$NMB_LC_CM[20] = ""
pivot2$NMB_LC_CM[20] = "NO REGISTRO"
## Convirtiendo en cero los NA's
pivot2$`Alto Deficit`<- ifelse(is.na(pivot2$`Alto Deficit`), 0, pivot2$`Alto Deficit`)
pivot2$Superavit <- ifelse(is.na(pivot2$Superavit), 0, pivot2$Superavit)
pivot2$`Medio Superavit` <- ifelse(is.na(pivot2$`Medio Superavit`), 0, pivot2$`Medio Superavit`)
pivot2$`Alto Superavit` <- ifelse(is.na(pivot2$`Alto Superavit`), 0, pivot2$`Alto Superavit`)
pivot2$`Medio Deficit` <- ifelse(is.na(pivot2$`Medio Deficit`), 0, pivot2$`Medio Deficit`)
pivot2$Deficit <- ifelse(is.na(pivot2$Deficit), 0, pivot2$Deficit)
pivot2$Equilibrio <- ifelse(is.na(pivot2$Equilibrio), 0, pivot2$Equilibrio)
pivot2;pivot3 <- pivot2[,-(1)]
pivot3 <- as.data.frame(pivot3)
rownames(pivot3) <- pivot2$NMB_LC_CM
###--Heatmap
matrix_pivot2 <- as.matrix(pivot3)
heatmap(matrix_pivot2, scale = "column",
main = "Heatmap tabla contingencia indicador csp",
Colv = NA, Rowv = NA, cexRow = 1, cexCol = 0.8,margins = c(8,1));library(factoextra)
pca_data2 <- prcomp(pivot3, scale = T)
fviz_eig(pca_data2)fviz_pca_ind(pca_data2,
col.ind = "cos2", # Color by the quality of representation
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
);fviz_pca_var(pca_data2,
col.var = "contrib", # Color by contributions to the PC
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
);fviz_pca_biplot(pca_data2, repel = TRUE,
col.var = "#2E9FDF", # Variables color
col.ind = "#696969" # Individuals color
)#### analisis de tablas cruzadas
pivot_df2$NMB_LC_CM <- as.character(pivot_df2$NMB_LC_CM)
pivot_df2$NMB_LC_CM[124:130] <- "NO REGISTRADO"
pivot_df2$NMB_LC_CM;## [1] "ANTONIO NARIÑO" "ANTONIO NARIÑO" "ANTONIO NARIÑO"
## [4] "ANTONIO NARIÑO" "BARRIOS UNIDOS" "BARRIOS UNIDOS"
## [7] "BARRIOS UNIDOS" "BARRIOS UNIDOS" "BARRIOS UNIDOS"
## [10] "BARRIOS UNIDOS" "BARRIOS UNIDOS" "BOSA"
## [13] "BOSA" "BOSA" "BOSA"
## [16] "BOSA" "BOSA" "BOSA"
## [19] "CANDELARIA" "CANDELARIA" "CANDELARIA"
## [22] "CANDELARIA" "CANDELARIA" "CANDELARIA"
## [25] "CHAPINERO" "CHAPINERO" "CHAPINERO"
## [28] "CHAPINERO" "CHAPINERO" "CHAPINERO"
## [31] "CHAPINERO" "CIUDAD BOLIVAR" "CIUDAD BOLIVAR"
## [34] "CIUDAD BOLIVAR" "CIUDAD BOLIVAR" "CIUDAD BOLIVAR"
## [37] "CIUDAD BOLIVAR" "CIUDAD BOLIVAR" "ENGATIVA"
## [40] "ENGATIVA" "ENGATIVA" "ENGATIVA"
## [43] "ENGATIVA" "ENGATIVA" "ENGATIVA"
## [46] "FONTIBON" "FONTIBON" "FONTIBON"
## [49] "FONTIBON" "FONTIBON" "FONTIBON"
## [52] "FONTIBON" "KENNEDY" "KENNEDY"
## [55] "KENNEDY" "KENNEDY" "KENNEDY"
## [58] "KENNEDY" "KENNEDY" "LOS MARTIRES"
## [61] "LOS MARTIRES" "LOS MARTIRES" "LOS MARTIRES"
## [64] "LOS MARTIRES" "LOS MARTIRES" "LOS MARTIRES"
## [67] "PUENTE ARANDA" "PUENTE ARANDA" "PUENTE ARANDA"
## [70] "PUENTE ARANDA" "PUENTE ARANDA" "RAFAEL URIBE URIBE"
## [73] "RAFAEL URIBE URIBE" "RAFAEL URIBE URIBE" "RAFAEL URIBE URIBE"
## [76] "RAFAEL URIBE URIBE" "RAFAEL URIBE URIBE" "RAFAEL URIBE URIBE"
## [79] "SAN CRISTOBAL" "SAN CRISTOBAL" "SAN CRISTOBAL"
## [82] "SAN CRISTOBAL" "SAN CRISTOBAL" "SAN CRISTOBAL"
## [85] "SAN CRISTOBAL" "SANTA FE" "SANTA FE"
## [88] "SANTA FE" "SANTA FE" "SANTA FE"
## [91] "SANTA FE" "SANTA FE" "SUBA"
## [94] "SUBA" "SUBA" "SUBA"
## [97] "SUBA" "SUBA" "SUBA"
## [100] "TEUSAQUILLO" "TEUSAQUILLO" "TEUSAQUILLO"
## [103] "TEUSAQUILLO" "TEUSAQUILLO" "TUNJUELITO"
## [106] "TUNJUELITO" "TUNJUELITO" "TUNJUELITO"
## [109] "TUNJUELITO" "USAQUEN" "USAQUEN"
## [112] "USAQUEN" "USAQUEN" "USAQUEN"
## [115] "USAQUEN" "USAQUEN" "USME"
## [118] "USME" "USME" "USME"
## [121] "USME" "USME" "USME"
## [124] "NO REGISTRADO" "NO REGISTRADO" "NO REGISTRADO"
## [127] "NO REGISTRADO" "NO REGISTRADO" "NO REGISTRADO"
## [130] "NO REGISTRADO"
pivot_df2$Categorias_indicador_csp <- as.character(pivot_df2$Categorias_indicador_csp)
library(CGPfunctions)
PlotXTabs2(pivot_df2,NMB_LC_CM,Categorias_indicador_csp,
x.axis.orientation = "vertical", label.text.size = 3);## `mutate_if()` ignored the following grouping variables:
## Column `x`
## `mutate_if()` ignored the following grouping variables:
## Column `x`
##- Arboles de proporción
library(vtree)
vtree(pivot_df2,"Categorias_indicador_csp", sortfill = T);vtree(pivot_df2,"NMB_LC_CM", sortfill = T)summary(df);## DPTO_CCDGO MPIO_CCDGO CLAS_CCDGO SETR_CCDGO
## Min. :11 Min. :1 Min. :1.000 Min. : 0.000000
## 1st Qu.:11 1st Qu.:1 1st Qu.:1.000 1st Qu.: 0.000000
## Median :11 Median :1 Median :1.000 Median : 0.000000
## Mean :11 Mean :1 Mean :1.002 Mean : 0.009653
## 3rd Qu.:11 3rd Qu.:1 3rd Qu.:1.000 3rd Qu.: 0.000000
## Max. :11 Max. :1 Max. :2.000 Max. :11.000000
##
## SECR_CCDGO ZU_CCDGO SETU_CCDGO SECU_CCDGO
## Min. :0.000000 Min. : 0.00000 Min. : 1 Min. : 1.00
## 1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:2535 1st Qu.: 2.00
## Median :0.000000 Median : 0.00000 Median :4525 Median : 3.00
## Mean :0.004239 Mean : 0.01661 Mean :4759 Mean : 4.07
## 3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:6402 3rd Qu.: 6.00
## Max. :5.000000 Max. :15.00000 Max. :9222 Max. :25.00
##
## MANZ_CCDGO AG_CCDGO DATO_ANM VERSION
## Min. : 1.00 Min. : 53793 Length:43408 Min. :2018
## 1st Qu.: 5.00 1st Qu.:145292 Class :character 1st Qu.:2018
## Median :10.00 Median :156776 Mode :character Median :2018
## Mean :13.59 Mean :158387 Mean :2018
## 3rd Qu.:18.00 3rd Qu.:168539 3rd Qu.:2018
## Max. :92.00 Max. :253743 Max. :2018
##
## AREA LATITUD LONGITUD DENSIDAD
## Min. : 32 Min. :3.890 Min. :-74.36 Min. :0.00000
## 1st Qu.: 1479 1st Qu.:4.569 1st Qu.:-74.15 1st Qu.:0.01954
## Median : 2624 Median :4.618 Median :-74.11 Median :0.04790
## Mean : 7333 Mean :4.625 Mean :-74.12 Mean :0.05215
## 3rd Qu.: 5155 3rd Qu.:4.685 3rd Qu.:-74.09 3rd Qu.:0.07974
## Max. :9064324 Max. :4.826 Max. :-74.01 Max. :0.57348
##
## CTNENCUEST TP3_1_SI TP3_2_NO TP3A_RI TP3B_TCN
## Min. : 0.00 Min. :0 Min. : 0.00 Min. :0 Min. :0
## 1st Qu.: 20.00 1st Qu.:0 1st Qu.: 20.00 1st Qu.:0 1st Qu.:0
## Median : 41.00 Median :0 Median : 41.00 Median :0 Median :0
## Mean : 62.78 Mean :0 Mean : 62.78 Mean :0 Mean :0
## 3rd Qu.: 69.00 3rd Qu.:0 3rd Qu.: 69.00 3rd Qu.:0 3rd Qu.:0
## Max. :4619.00 Max. :0 Max. :4619.00 Max. :0 Max. :0
##
## TP4_1_SI TP4_2_NO TP9_1_USO TP9_2_USO
## Min. : 0.0000 Min. : 0.00 Min. : 0.00 Min. : 0.0000
## 1st Qu.: 0.0000 1st Qu.: 20.00 1st Qu.: 17.00 1st Qu.: 0.0000
## Median : 0.0000 Median : 41.00 Median : 36.00 Median : 0.0000
## Mean : 0.5643 Mean : 62.22 Mean : 57.13 Mean : 0.8724
## 3rd Qu.: 0.0000 3rd Qu.: 69.00 3rd Qu.: 62.00 3rd Qu.: 1.0000
## Max. :180.0000 Max. :4619.00 Max. :4615.00 Max. :60.0000
##
## TP9_3_USO TP9_4_USO TP9_2_1_MI TP9_2_2_MI
## Min. : 0.000 Min. :0 Min. : 0.00000 Min. : 0.0000
## 1st Qu.: 0.000 1st Qu.:0 1st Qu.: 0.00000 1st Qu.: 0.0000
## Median : 2.000 Median :0 Median : 0.00000 Median : 0.0000
## Mean : 4.779 Mean :0 Mean : 0.08955 Mean : 0.5437
## 3rd Qu.: 6.000 3rd Qu.:0 3rd Qu.: 0.00000 3rd Qu.: 0.0000
## Max. :217.000 Max. :0 Max. :22.00000 Max. :56.0000
##
## TP9_2_3_MI TP9_2_4_MI TP9_2_9_MI TP9_3_1_NO
## Min. : 0.0000 Min. : 0.000000 Min. :0.000000 Min. : 0.0000
## 1st Qu.: 0.0000 1st Qu.: 0.000000 1st Qu.:0.000000 1st Qu.: 0.0000
## Median : 0.0000 Median : 0.000000 Median :0.000000 Median : 0.0000
## Mean : 0.2357 Mean : 0.001912 Mean :0.001567 Mean : 0.4621
## 3rd Qu.: 0.0000 3rd Qu.: 0.000000 3rd Qu.:0.000000 3rd Qu.: 0.0000
## Max. :46.0000 Max. :15.000000 Max. :4.000000 Max. :52.0000
##
## TP9_3_2_NO TP9_3_3_NO TP9_3_4_NO TP9_3_5_NO
## Min. : 0.000 Min. : 0.000 Min. : 0.00000 Min. : 0.0000
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.00000 1st Qu.: 0.0000
## Median : 0.000 Median : 0.000 Median : 0.00000 Median : 0.0000
## Mean : 2.263 Mean : 1.376 Mean : 0.01168 Mean : 0.1461
## 3rd Qu.: 2.000 3rd Qu.: 1.000 3rd Qu.: 0.00000 3rd Qu.: 0.0000
## Max. :180.000 Max. :173.000 Max. :24.00000 Max. :19.0000
##
## TP9_3_6_NO TP9_3_7_NO TP9_3_8_NO TP9_3_9_NO
## Min. : 0.0000 Min. : 0.0000 Min. : 0.000000 Min. : 0.00000
## 1st Qu.: 0.0000 1st Qu.: 0.0000 1st Qu.: 0.000000 1st Qu.: 0.00000
## Median : 0.0000 Median : 0.0000 Median : 0.000000 Median : 0.00000
## Mean : 0.2897 Mean : 0.1026 Mean : 0.002995 Mean : 0.00569
## 3rd Qu.: 0.0000 3rd Qu.: 0.0000 3rd Qu.: 0.000000 3rd Qu.: 0.00000
## Max. :109.0000 Max. :36.0000 Max. :11.000000 Max. :12.00000
##
## TP9_3_10_N TP9_3_99_N TVIVIENDA TP14_1_TIP
## Min. : 0.0000 Min. :0.00000 Min. : 0 Min. : 0.00
## 1st Qu.: 0.0000 1st Qu.:0.00000 1st Qu.: 17 1st Qu.: 5.00
## Median : 0.0000 Median :0.00000 Median : 37 Median : 12.00
## Mean : 0.1095 Mean :0.01037 Mean : 58 Mean : 19.03
## 3rd Qu.: 0.0000 3rd Qu.:0.00000 3rd Qu.: 63 3rd Qu.: 23.00
## Max. :21.0000 Max. :4.00000 Max. :4618 Max. :1773.00
##
## TP14_2_TIP TP14_3_TIP TP14_4_TIP TP14_5_TIP
## Min. : 0.00 Min. : 0.000 Min. :0.000000 Min. :0.000000
## 1st Qu.: 2.00 1st Qu.: 0.000 1st Qu.:0.000000 1st Qu.:0.000000
## Median : 13.00 Median : 1.000 Median :0.000000 Median :0.000000
## Mean : 35.43 Mean : 3.496 Mean :0.004055 Mean :0.003893
## 3rd Qu.: 34.00 3rd Qu.: 4.000 3rd Qu.:0.000000 3rd Qu.:0.000000
## Max. :4571.00 Max. :231.000 Max. :4.000000 Max. :5.000000
##
## TP14_6_TIP TP15_1_OCU TP15_2_OCU TP15_3_OCU
## Min. : 0.00000 Min. : 0.00 Min. : 0.0000 Min. : 0.000
## 1st Qu.: 0.00000 1st Qu.: 16.00 1st Qu.: 0.0000 1st Qu.: 0.000
## Median : 0.00000 Median : 35.00 Median : 0.0000 Median : 0.000
## Mean : 0.03845 Mean : 53.93 Mean : 0.7544 Mean : 0.591
## 3rd Qu.: 0.00000 3rd Qu.: 60.00 3rd Qu.: 0.0000 3rd Qu.: 0.000
## Max. :68.00000 Max. :2846.00 Max. :311.0000 Max. :149.000
##
## TP15_4_OCU TP16_HOG TP19_EE_1 TP19_EE_2
## Min. : 0.000 Min. : 0.00 Min. : 0.0 Min. : 0.0000
## 1st Qu.: 0.000 1st Qu.: 18.00 1st Qu.: 16.0 1st Qu.: 0.0000
## Median : 0.000 Median : 39.00 Median : 35.0 Median : 0.0000
## Mean : 2.722 Mean : 57.83 Mean : 53.8 Mean : 0.1294
## 3rd Qu.: 2.000 3rd Qu.: 66.00 3rd Qu.: 60.0 3rd Qu.: 0.0000
## Max. :1459.000 Max. :2863.00 Max. :2844.0 Max. :102.0000
##
## TP19_EE_E1 TP19_EE_E2 TP19_EE_E3 TP19_EE_E4
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.000
## 1st Qu.: 0.00 1st Qu.: 0.00 1st Qu.: 0.00 1st Qu.: 0.000
## Median : 0.00 Median : 1.00 Median : 0.00 Median : 0.000
## Mean : 4.49 Mean : 21.11 Mean : 18.66 Mean : 6.075
## 3rd Qu.: 1.00 3rd Qu.: 28.00 3rd Qu.: 16.00 3rd Qu.: 0.000
## Max. :672.00 Max. :2795.00 Max. :1659.00 Max. :2059.000
##
## TP19_EE_E5 TP19_EE_E6 TP19_EE_E9 TP19_ACU_1
## Min. : 0.000 Min. : 0.000 Min. : 0.0000 Min. : 0.00
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.0000 1st Qu.: 16.00
## Median : 0.000 Median : 0.000 Median : 0.0000 Median : 34.00
## Mean : 1.921 Mean : 1.407 Mean : 0.1376 Mean : 53.68
## 3rd Qu.: 0.000 3rd Qu.: 0.000 3rd Qu.: 0.0000 3rd Qu.: 60.00
## Max. :1212.000 Max. :485.000 Max. :84.0000 Max. :2842.00
##
## TP19_ACU_2 TP19_ALC_1 TP19_ALC_2 TP19_GAS_1
## Min. : 0.0000 Min. : 0.00 Min. : 0.0000 Min. : 0.00
## 1st Qu.: 0.0000 1st Qu.: 15.00 1st Qu.: 0.0000 1st Qu.: 14.00
## Median : 0.0000 Median : 34.00 Median : 0.0000 Median : 32.00
## Mean : 0.2565 Mean : 53.55 Mean : 0.3814 Mean : 50.29
## 3rd Qu.: 0.0000 3rd Qu.: 60.00 3rd Qu.: 0.0000 3rd Qu.: 56.00
## Max. :214.0000 Max. :2844.00 Max. :219.0000 Max. :2830.00
##
## TP19_GAS_2 TP19_GAS_9 TP19_RECB1 TP19_RECB2
## Min. : 0.000 Min. : 0.0000 Min. : 0.00 Min. : 0.000
## 1st Qu.: 0.000 1st Qu.: 0.0000 1st Qu.: 16.00 1st Qu.: 0.000
## Median : 1.000 Median : 0.0000 Median : 34.00 Median : 0.000
## Mean : 2.969 Mean : 0.6762 Mean : 53.63 Mean : 0.304
## 3rd Qu.: 3.000 3rd Qu.: 1.0000 3rd Qu.: 60.00 3rd Qu.: 0.000
## Max. :420.000 Max. :320.0000 Max. :2846.00 Max. :186.000
##
## TP19_INTE1 TP19_INTE2 TP19_INTE9 TP27_PERSO
## Min. : 0.00 Min. : 0.00 Min. : 0.0000 Min. : 0.0
## 1st Qu.: 9.00 1st Qu.: 2.00 1st Qu.: 0.0000 1st Qu.: 51.0
## Median : 23.00 Median : 8.00 Median : 0.0000 Median : 113.0
## Mean : 40.27 Mean : 12.98 Mean : 0.6844 Mean : 164.4
## 3rd Qu.: 42.00 3rd Qu.: 17.00 3rd Qu.: 1.0000 3rd Qu.: 191.0
## Max. :2230.00 Max. :1300.00 Max. :320.0000 Max. :8330.0
##
## PERSONAS_L PERSONAS_S TP32_1_SEX TP32_2_SEX
## Min. :0 Min. : 0.0 Min. : 0.00 Min. : 0.00
## 1st Qu.:0 1st Qu.: 51.0 1st Qu.: 25.00 1st Qu.: 26.00
## Median :0 Median : 113.0 Median : 55.00 Median : 58.00
## Mean :0 Mean : 164.4 Mean : 78.41 Mean : 86.01
## 3rd Qu.:0 3rd Qu.: 191.0 3rd Qu.: 92.00 3rd Qu.: 99.00
## Max. :0 Max. :8330.0 Max. :3787.00 Max. :4543.00
##
## TP34_1_EDA TP34_2_EDA TP34_3_EDA TP34_4_EDA
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
## 1st Qu.: 5.00 1st Qu.: 6.00 1st Qu.: 9.00 1st Qu.: 7.00
## Median : 13.00 Median : 16.00 Median : 22.00 Median : 17.00
## Mean : 19.74 Mean : 23.54 Mean : 31.45 Mean : 27.07
## 3rd Qu.: 24.00 3rd Qu.: 28.00 3rd Qu.: 38.00 3rd Qu.: 31.00
## Max. :1440.00 Max. :1400.00 Max. :1920.00 Max. :1857.00
##
## TP34_5_EDA TP34_6_EDA TP34_7_EDA TP34_8_EDA
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.000
## 1st Qu.: 5.00 1st Qu.: 5.00 1st Qu.: 3.00 1st Qu.: 1.000
## Median : 13.00 Median : 13.00 Median : 8.00 Median : 4.000
## Mean : 21.38 Mean : 19.56 Mean : 12.33 Mean : 6.198
## 3rd Qu.: 24.00 3rd Qu.: 23.00 3rd Qu.: 15.00 3rd Qu.: 8.000
## Max. :1031.00 Max. :676.00 Max. :393.00 Max. :208.000
##
## TP34_9_EDA TP51PRIMAR TP51SECUND TP51SUPERI
## Min. : 0.000 Min. : 0.00 Min. : 0.00 Min. : 0.00
## 1st Qu.: 0.000 1st Qu.: 0.00 1st Qu.: 0.00 1st Qu.: 0.00
## Median : 2.000 Median : 23.00 Median : 0.00 Median : 22.00
## Mean : 3.142 Mean : 31.19 Mean : 28.35 Mean : 43.58
## 3rd Qu.: 4.000 3rd Qu.: 43.00 3rd Qu.: 0.00 3rd Qu.: 45.00
## Max. :110.000 Max. :2094.00 Max. :4161.00 Max. :2793.00
##
## TP51POSTGR TP51_13_ED TP51_99_ED CD_LC_CM
## Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. : 1.00
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 6.00
## Median : 0.000 Median : 1.000 Median : 2.000 Median :10.00
## Mean : 7.644 Mean : 2.523 Mean : 3.557 Mean :10.05
## 3rd Qu.: 0.000 3rd Qu.: 3.000 3rd Qu.: 5.000 3rd Qu.:14.00
## Max. :1490.000 Max. :178.000 Max. :1130.000 Max. :19.00
## NA's :77
## NMB_LC_CM TP_LC_CM Shape_Leng
## CIUDAD BOLIVAR: 5248 Length:43408 Min. :0.0002113
## KENNEDY : 4966 Class :character 1st Qu.:0.0015705
## SUBA : 4740 Mode :character Median :0.0021684
## ENGATIVA : 4058 Mean :0.0027679
## BOSA : 3356 3rd Qu.:0.0029996
## (Other) :20963 Max. :0.1441678
## NA's : 77
## Shape_Area COD_RDTM geometry Deficit_dpf_aprox1
## Min. :2.600e-09 Min. :1.1e+23 Length:43408 Min. :-4.71128
## 1st Qu.:1.205e-07 1st Qu.:1.1e+23 Class :character 1st Qu.: 0.01940
## Median :2.139e-07 Median :1.1e+23 Mode :character Median : 0.05430
## Mean :5.977e-07 Mean :1.1e+23 Mean : 0.08841
## 3rd Qu.:4.201e-07 3rd Qu.:1.1e+23 3rd Qu.: 0.09862
## Max. :7.388e-04 Max. :1.1e+23 Max. : 5.04675
##
## Deficit_dpf_aprox2 Deficit_dpf Categorias_indicador_dpf
## Min. :-0.124853 Min. : 0.00 Deficit :26167
## 1st Qu.: 0.006293 1st Qu.: 48.48 Equilibrio :15067
## Median : 0.014447 Median : 48.84 Superavit : 1852
## Mean : 0.023034 Mean : 49.19 Medio Superavit: 299
## 3rd Qu.: 0.025390 3rd Qu.: 49.29 Alto Superavit : 12
## Max. : 1.181064 Max. :100.00 Medio Deficit : 9
## (Other) : 2
## Deficit_csp TP19_ACU_1.rescaled TP19_ALC_1.rescaled TP19_GAS_1.rescaled
## Min. : 0.00 Min. :0.00000 Min. :0.000000 Min. :0.000000
## 1st Qu.: 80.71 1st Qu.:0.00563 1st Qu.:0.005274 1st Qu.:0.004947
## Median : 88.71 Median :0.01196 Median :0.011955 Median :0.011307
## Mean : 77.38 Mean :0.01889 Mean :0.018830 Mean :0.017770
## 3rd Qu.: 92.74 3rd Qu.:0.02111 3rd Qu.:0.021097 3rd Qu.:0.019788
## Max. :100.00 Max. :1.00000 Max. :1.000000 Max. :1.000000
##
## Poblacion_fav_aprox_1 Poblacion_nofav_aprox_1 TP19_RECB1.rescaled
## Min. :0.00000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.03143 1st Qu.:0.003919 1st Qu.:0.005622
## Median :0.07037 Median :0.011905 Median :0.011947
## Mean :0.11131 Mean :0.022900 Mean :0.018844
## 3rd Qu.:0.12280 3rd Qu.:0.025409 3rd Qu.:0.021082
## Max. :5.68700 Max. :4.954359 Max. :1.000000
##
## TP19_INTE1.rescaled TP19_EE_2.rescaled TP19_ACU_2.rescaled TP19_ALC_2.rescaled
## Min. :0.000000 Min. :0.000000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.004036 1st Qu.:0.000000 1st Qu.:0.000000 1st Qu.:0.000000
## Median :0.010314 Median :0.000000 Median :0.000000 Median :0.000000
## Mean :0.018056 Mean :0.001269 Mean :0.001199 Mean :0.001741
## 3rd Qu.:0.018834 3rd Qu.:0.000000 3rd Qu.:0.000000 3rd Qu.:0.000000
## Max. :1.000000 Max. :1.000000 Max. :1.000000 Max. :1.000000
##
## TP19_GAS_2.rescaled Poblacion_fav_aprox_2 Poblacion_nofav_aprox_2
## Min. :0.000000 Min. :0.000000 Min. :0.000000
## 1st Qu.:0.000000 1st Qu.:0.009483 1st Qu.:0.002292
## Median :0.002381 Median :0.019811 Median :0.004853
## Mean :0.007069 Mean :0.030689 Mean :0.007656
## 3rd Qu.:0.007143 3rd Qu.:0.034077 3rd Qu.:0.008715
## Max. :1.000000 Max. :1.780193 Max. :0.808863
##
## TP19_RECB2.rescaled Categorias_indicador_csp
## Min. :0.000000 Alto Deficit : 5005
## 1st Qu.:0.000000 Medio Deficit : 202
## Median :0.000000 Deficit : 188
## Mean :0.001635 Equilibrio : 68
## 3rd Qu.:0.000000 Superavit : 415
## Max. :1.000000 Medio Superavit: 4563
## Alto Superavit :32967
write.csv(df,"//Users//Thony//Documents//Data_Analyst_DANE//NOV 2021//df_m_1er_ind_MGN20211116.csv")